<template>
	<view :class="lang">
		<u-navbar :is-fixed="true" :title="title" back-icon-name="arrow-left">
			<view class="slot-wrap greenbg heigh150">
				<view class="u-navbar-centent-slot">
				</view>
			</view>
		</u-navbar>

	
		<scroll-view class="resultview" scroll-y="true">
			<view class="resultview-box">
				<view class="resultview-box-item" v-for="(item,index) in recordjson" :key="index">
					<view v-if="lang == 'cn'" class="resultview-box-title">
						<view class="">
							{{title}}
						</view>
						<view class="resultview-recordnum">
							<text>{{item.recordnum}}</text>
							<text>{{ $t('resultstxt.分') }}</text>
						</view>
					</view>
					
					<view v-else class="resultview-box-title">
						<view class="resultview-recordnum" style="margin-right: 15rpx; margin-left: 290rpx; direction: rtl;">
							<text>{{item.recordnum}}</text>
							<text>{{ $t('resultstxt.分') }}</text>
						</view>
						<view class="">
							{{title}}
						</view>
					</view>
					<view class="resultview-box-content">
						<view class="time">
							<view class="">
								{{ $t('resultstxt.考试用时') }}
							</view>
							<view class="time-num">
								{{item.timeuse}}
							</view>
						</view>
						<view class="date">
							<view class="">
								{{ $t('resultstxt.考试日期') }}
							</view>
							<view class="date-num">
								{{item.adddate | formatDate}}
							</view>
						</view>
					</view>
					
				</view>
			</view>
		</scroll-view>
        
		<view class="rebutton">
			<view class="buttonre" @click="reexamlink()">
				{{ reexam }}
			</view>
			<!-- <button class="buttonre  font-25" @click="reexamlink()"><text>{{ reexam }}</text></button> -->
		</view>
	</view>
</template>

<script>
	//#ifdef APP-PLUS
	import {
		isOpen,
		openDb,
		addTab,
		mergeSql,
		getDataList,
		addTabItem,
		closeSQL,
		deleteInformationType,
		getTable,
		getCount,
		updateSQL,
		isTable,
		selectDataList
	} from '@/js_sdk/lyz-sqlite/index.js';
	import {
		getFileName,
		getimgname
	} from '../../common/imgtool.js';
	//#endif
	import {
		getCarType,
		getArrEqual,
		getArrload
	} from '../../common/savetool.js';

	export default {
		data() {
			return {
				lang: this.$i18n.locale,
				title: this.$t('resultstxt.考试成绩'),
				reexam: this.$t('resultstxt.继续科目一考试'),
				cartype: '',
				subject: '',
				kemu: '',
				lolang: '',
				recordjson: [],
				lang: "",
			}
		},
		onLoad(options) {
			var that = this;
			var kemu = options.kemu;
			that.kemu = kemu;

			try {
				const value = uni.getStorageSync('lang_key');
				that.lang = value
				console.log("app onlaunch", value);
				if (value) {
					that.$i18n.locale = value;
					that.lang = value;
					if (value == 'cn') {
						that.lolang = 'CN';
					}
					if (value == 'uy') {
						that.lolang = 'UG';
					}
					if (value == 'kz') {
						that.lolang = 'KAZ';
					}
					if (res.data == 'cn') {
						that.langheight = 20;
					} else {
						that.langheight = 38;
					}
				} else {
					uni.reLaunch({
						url: 'pages/setting/setting'
					});
				}
			} catch (e) {
				// error
				uni.reLaunch({
					url: 'pages/setting/setting'
				});
			}

			// uni.getStorage({
			// 	key: 'lang_key',
			// 	success: function(res) {
			// 		console.log(res.data);
			// 		that.$i18n.locale = res.data;
			// 		that.lang = res.data;
			// 		if (that.$i18n.locale == 'cn') {
			// 			that.lolang = 'CN';
			// 		}
			// 		if (that.$i18n.locale == 'uy') {
			// 			that.lolang = 'UG';
			// 		}
			// 		if (that.$i18n.locale == 'kz') {
			// 			that.lolang = 'KAZ';
			// 		}
			// 		if (res.data == 'cn') {
			// 			that.langheight = 20;
			// 		} else {
			// 			that.langheight = 38;
			// 		}
			// 	},
			// 	fail() {}
			// });
			
			// 题库年份
			uni.getStorage({
				key: 'year_key',
				success: function(res) {
					console.log("年份", res.data)
					that.year =res.data
				},
				fail() {
					that.$u.route({
						url: 'pages/setting/setting',
						params: {}
					});
				}
			});
			
			uni.getStorage({
				key: 'cart_type',
				success: function(res) {
					console.log(res, '=====');
					console.log(res.data);
					console.log('getCarType--=', getCarType(res.data));
					that.cartype = res.data;
					that.subject = getCarType(res.data);
					if (kemu == 1) {
						that.reexam = that.$t('resultstxt.继续科目一考试')
					}
					if (kemu == 4) {
						that.reexam = that.$t('resultstxt.继续科目四考试')
					}
					if (kemu == 0) {
						that.reexam = that.$t('keeping.继续资格证考试')
					}
					
					// 注释1
					// //#ifdef APP-PLUS
					// if (isOpen('data')) {
					// 	//数据库已打开
					// 	console.log('数据库已打开');
					// 	//that.dbcount(that.kemu);
					// 	that.dbid(kemu);
					// 	console.log('kemu', kemu);

					// } else {
					// 	//数据库没有打开  先打开
					// 	console.log('数据库未打开');
					// 	that.openDb();
					// }
					// //#endif
					
					
					that.minirecord(kemu);
				}
			});

		},

		// onBackPress(options) {
		// 	uni.reLaunch({
		// 		url: '../index/index'
		// 	});
		// 	// if (options.from === 'navigateBack') {
		// 	// 	return false;
		// 	// }

		// 	return true;
		// },
		methods: {
			back() {
				// uni.reLaunch({
				// 	url: '../index/index'
				// });
			},
			//打开数据库
			openDb() {
				var that = this;
				if (isOpen('data')) return;
				openDb('data').then(res => {
					console.log(res);
					that.dbid(kemu);
				});
			},
			minirecord(kemu) {
				var that = this;
				uni.getStorage({
					key: that.subject + '_examlist_' + that.lang + '_' + that.kemu,
					success: function(res) {
						console.log("_examlist_", res.data);
						that.recordjson = res.data;
					
					},
					fail(e) {

					}
				});
			},
			dbid() {
				var that = this;
				var sql = "select * from record where subject='" + that.subject + "' and tlang = '" + that.lolang +
					"' and kemu = '" + that.kemu +"'";
				plus.sqlite.selectSql({
					name: 'data',
					sql: sql,
					success(e) {
						console.log(sql);
						console.log(e.length);
						if (e.length == 0) {
							console.log('没有记录！');
						} else {
							//that.subarr = e;
							that.recordjson = e;
							that.recordjson.forEach(item=>{
								console.log("时间戳",item.adddate)
								
							})
							console.log("考试记录",e);
						}
						//console.log(e.length)
					},
					fail(e) {
						console.log(e);
					}
				});
			},
			reexamlink() {
				var that = this;
				var kemu = that.kemu;
				uni.reLaunch({
					url: 'exam?kemu=' + kemu
				})
			}



		},
		//时间戳的处理
		filters: {
			formatDate: function(value) {
				console.log(value);
				var ms = Number(value);
				var date = new Date(ms);
				//date.setTime(value);
				var month = date.getMonth() + 1;
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				// var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
				//     " " + hours + ":" + minutes;
				return time;
			}
		
		}

	}
</script>

<style scoped lang="scss">
	page {
		background: #F7F7F7;
	}

	.resultslayout {
		width: 720rpx;
		margin: 20rpx auto;
		border-radius: 20rpx;
		background: #f5f5f5;
		height: 70vh;
	}

	.resultsrow {
		width: 680rpx;
		margin: 0 auto;
	}

	.kong {
		width: 680rpx;
		height: 30rpx;
	}

	.resultstitle {
		width: 680rpx;
		display: flex;
		justify-content: space-between;
		flex-flow: row wrap;
		border: 1rpx solid #d9d9d9;
		background: #f7f7f7;
		border-radius: 20rpx;
	}

	.resultsitem {
		width: 225rpx;
		display: inline-block;
		text-align: center;
		color: #0cd34e;
		padding: 10rpx 0rpx;
	}

	.kz .resultsitem {
		padding-top: 18rpx !important;
	}

	.uy .resultsitem {
		padding-top: 18rpx !important;
	}

	.resultcon {
		width: 680rpx;
		display: flex;
		justify-content: space-between;
		flex-flow: row wrap;
	}

	.resultconrow {
		width: 226rpx;
		display: inline-block;
		text-align: center;
		height: 60rpx;
	}

	.laycn {
		font-family: 'Arial' !important;
		direction: ltr !important;
	}

	.resultview {
		height: 80vh;
		background: #F7F7F7;
		
		.resultview-box{
			width: 100%;
			height: 100%;
			padding: 30rpx;
			box-sizing: border-box;
			.resultview-box-item{
				width: 690rpx;
				height: 207rpx;
				background: #FFFFFF;
				// background-color: pink;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				opacity: 1;
				margin-bottom: 30rpx;
				padding: 30rpx;
				box-sizing: border-box;
				.resultview-box-title{
					width: 630rpx;
					font-size: 26rpx;
					// font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #2B2B2B;
					line-height: 30rpx;
					display: flex;
					padding-bottom: 20rpx;
					box-sizing: border-box;
					border-bottom: 1rpx solid #EAEAEA;
					.resultview-recordnum{
						font-size: 28rpx;
						// font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #0DA0FF;
						line-height: 33rpx;
						margin-left: 20rpx;
						float:right;
					}
				}
				.resultview-box-content{
					display: flex;
					width: 500rpx;
					justify-content: space-between;
					margin-top: 20rpx;
					margin-left: 70rpx;
				    .time{
						font-size: 24rpx;
						// font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #2B2B2B;
						line-height: 28rpx;
						text-align: center;
						.time-num{
							font-size: 28rpx;
							// font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #0DA0FF;
							line-height: 33rpx;
							margin-top: 10rpx;
						}
					}
					.date{
						font-size: 24rpx;
						// font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #2B2B2B;
						line-height: 28rpx;
						text-align: center;
						.date-num{
							font-size: 28rpx;
							// font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #0DA0FF;
							line-height: 33rpx;
							margin-top: 10rpx;
						}
					}
				}
			}
		}
	}

	.rebutton {
		position: absolute;
		bottom: 50rpx;
		left: 0rpx;
		width: 750rpx;
		text-align: center;
	}

	.rebutton button::after {
		border: none;
	}

	.kz .rebutton button {
		padding-top: 5rpx;
	}

	.uy .rebutton button {
		padding-top: 5rpx;
	}

	.buttonre {
		width: 540rpx;
		height: 73rpx;
		background: linear-gradient(90deg, #75EFFF 0%, #3C89F2 100%);
		border-radius: 48rpx 48rpx 48rpx 48rpx;
		opacity: 1;
		margin: 0 auto;
		font-size: 28rpx;
		// font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 73rpx;
	}

	.buttonre text {
		display: inline-block;
		max-width: 600rpx;
		height: 60rpx;
		padding: 0 10rpx;
	}
</style>
